package route

import (
	"encoding/json"
	"net/http"

	"protocx/protobufx"

	"github.com/gin-gonic/gin"
)

type Proto struct {
}

func (p Proto) InitRoute(g *gin.RouterGroup) {
	group := g.Group("resp")
	group.GET("/json", p.json())
	group.GET("/protobuf", p.protobuf())
}
func (p Proto) json() gin.HandlerFunc {
	return func(c *gin.Context) {
		request := &protobufx.LoginRequest{Code: 12}
		marshal, err := json.Marshal(request)
		if err != nil {
			c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
			return
		}
		c.JSON(http.StatusOK, string(marshal))
	}
}
func (p Proto) protobuf() gin.HandlerFunc {
	return func(c *gin.Context) {
		request := &protobufx.LoginRequest{Code: 12}
		c.ProtoBuf(http.StatusOK, request)
	}
}
